<template>
	<view class="page tn-safe-area-inset-bottom" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
		<view class="top-bg"></view>
		<dawnBar title="住院费用记录"></dawnBar>
		<view class="page-container" style="padding-bottom: 140rpx;">
			<pBox @search="getPage()" :search="true"></pBox>
			<view class="order--wrap tn-margin-top-sm">
				<!-- 标签内容 -->
				<view class="list">
					<view class="list-item" v-for="(item,index) in list" :key="index">
						<view class="list-head tn-flex tn-flex-direction-row tn-flex-col-center tn-flex-row-between">
							<view @click="navDteail(item)">
								<text class="tn-color-black"></text>
								<text class="tn-color-dawn tn-text-lg tn-text-bold">{{ item.registerNo  || '' }}</text>
							</view>
							<view>
								<view class="justify-content-item ">
									<tn-tag v-if="item.procedureStatus === 'success'" backgroundColor="tn-main-gradient-dawn" fontColor="#FFFFFF"
										shape="circleLeft" width="auto">
										挂号成功
									</tn-tag>
									<tn-tag v-else-if="item.procedureStatus === 'refund'" backgroundColor="#000000" fontColor="#FFFFFF"
										shape="circleLeft" width="auto">
										已退号
									</tn-tag>
									<tn-tag v-else backgroundColor="tn-main-gradient-danger" fontColor="#FFFFFF"
										shape="circleLeft" width="auto">
										挂号失败
									</tn-tag>
								</view>
							</view>
						</view>
						<view class="list-content tn-flex tn-flex-nowrap tn-flex-col-center tn-flex-row-between">
							<view class="tn-flex tn-flex-nowrap  tn-flex-col-center tn-flex-row-left">
								<view @click="navDteail(item)" v-if="item.pictures && item.pictures.length > 0">
									<image mode="aspectFill" class="list-content-image" :src="item.pictures[0]">
								</view>
								<view class="">
									<view>
										<text class="tn-color-black">挂号单：</text>
										<text class="tn-color-black tn-text-bold">{{item.procedureNo || '' }}</text>
										<text class="tn-color-gray tn-padding-left-xs tn-padding-right-xs">|</text>
										<text class="tn-color-black">类型：</text>
										<text class="tn-text-bold">{{item.regType || '' }}</text>
									</view>
									<view class="tn-margin-top-xs">
										<text class="tn-color-black">科室：</text>
										<text class="tn-color-dawn tn-text-bold">{{ item.departmentName  || '' }}</text>
										<text class="tn-color-gray tn-padding-left-xs tn-padding-right-xs">|</text>
										<text class="tn-color-black">医生：</text>
										<text class="tn-color-dawn tn-text-bold">{{ item.doctorName  || '' }}</text>
									</view>
									<view>
										<text class="">就诊时间：</text>
										<text
											class="tn-color-red--dark tn-text-bold">{{ item.regDate }}</text>
										<text
											class="tn-color-red--dark tn-text-bold tn-padding-left-ss">{{ item.scheduleTime }}</text>
									</view>
									<view>
										<text class="tn-color-black">HIS结帐ID：</text>
										<text class="tn-color-black tn-text-bold">{{ item.procedureId  || '' }}</text>
									</view>
								</view>
							</view>

							<view @click="navDteail(item)"
								class="tn-flex tn-flex-nowrap  tn-flex-col-center tn-flex-row-left">
								<view class="tn-text-right">
									<text class="tn-margin-right-ss">¥</text>
									<text class="dawn-text-lg tn-text-bold dawn-color-red">{{ item.amount }}</text>
								</view>
							</view>
						</view>

						<view class="dawn-line tn-margin-top-sm"></view>
						<view
							class=" tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-between">
							<view class="justify-content-item tn-text-df">
								<text class="tn-color-black" v-if="item.payTime">
									<text class="tn-icon-time-fill tn-color-black"></text>
									{{ formatDateTime(item.payTime)  || '' }}
								</text>
							</view>
							<view
								class="tn-flex tn-flex-direction-row tn-flex-nowrap tn-flex-col-center tn-flex-row-right op-box">
								<tn-button @click="navDteail(item)" size="sm" class="dawn-btn-sm dawn-btn-sm__primary">
									<text class="tn-icon-send-fill">详情</text>
								</tn-button>
							</view>
						</view>
					</view>
				</view>

				<!-- 悬浮按钮-->
				<view class="tn-flex tn-footerfixed">
					<view class="tn-flex-1 justify-content-item tn-margin-sm tn-text-center">
						<tn-button @click="getPage()" class="dawn-btn-lg dawn-btn-lg__main">
							<text class="tn-icon-search-list-fill tn-padding-right-xs"></text>
							<text>查 询</text>
						</tn-button>
					</view>
				</view>
			</view>
			<view v-if="show">
				<dawnMsg :msg="msg"></dawnMsg>
			</view>
		</view>
		
		<!-- loading -->
		<dawnLoading :show="loading"></dawnLoading>

		<!-- 分页 -->
		<!-- <dawn-pagination ref="pagination" :current="queryData.pageNo" :total="total" @pagination="getPage" /> -->

		<!-- 悬浮按钮-->
		<NavBtn></NavBtn>
	</view>
</template>

<script>
	import page_mixin from '@/mixins/page_mixin.js'
	import dayjs from '@/plugin/dayjs/dayjs.min.js';
	import * as InhospitalApi from "@/api/hospital/inhospital.js";
	import * as ArticleApi from '@/api/cms/article.js';
	import * as api from '@/api/api.js';
	import * as config from "@/api/config.js";
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	const app = getApp();

	export default {
		name: 'order',
		mixins: [page_mixin],
		computed: mapGetters(['appConfig', 'uid', 'isLogin', 'userInfo','patientInfo']),
		data() {
			return {
				loading: false,
				show: false,
				msg: '',
				tabsIndex: 0,
				queryData: {
					pageSize: 100,
					pageNo: 1,
					patientId: '',
					patientName: ''
				},
				status: -1,
				dataText: '',
				list: []
			}
		},
		onLoad(options) {
			console.info("query onLoad")
			if (!this.isLogin) {
				toLogin();
				return;
			} else {
				// this.$nextTick(() => {
				// 	this.getPage();
				// })
			}
		},
		methods: {
			search(result) {
				if (result.code === 0) {
					this.queryData = result.data;
					this.queryData.pageNo = 1;
					this.queryData.pageSize = this.$refs.pagination.pageSize;
					// this.getPage();
				}
			},
			getPage: function(page) {
				let that = this;
				this.loading = true;
				this.show = false;
				this.$set(this, 'list', []);
				this.queryData.userId = this.patientInfo.openid;
				this.queryData.patientId = this.patientInfo.patientId;
				if(this.patientInfo.patientId === '35426'){
					this.queryData.patientId = '674323';
				}
				this.queryData.patientName = this.patientInfo.name;
				// this.queryData.beginDate = '2024-01-01';
				// this.queryData.endDate = '2024-12-31';
				
				InhospitalApi.payRecord(this.queryData).then(res => {
					this.loading = false;
					console.table(res);
					if (res.code === 0) {
						const l = res.data.list || [];
						if (l.length == 0) {
							that.show = true;
							that.msg = '暂无数据';
						}else {
							const array = l.filter((val) => (val.payStatus === 'payoff'));
							that.$set(that, 'list', array);
						}
					} else {
						that.show = true;
						that.msg = '暂无数据';
					}
				}).catch(err => {
					this.loading = false;
					this.show = true;
				})
			},
			navDteail(item) {
				uni.navigateTo({
					url: '/hosp/order/detail?orderNumber=' + item.registerNo
				})
			},
			formatDate: function(date) {
				return dayjs(date).format("YYYY-MM-DD");
			},
			formatDateTime: function(date) {
				return dayjs(date).format("YYYY-MM-DD HH:mm:ss");
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>